home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dragpic3 / form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-04-20  |  4.8 KB  |  151 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   5385
  5.    ClientLeft      =   660
  6.    ClientTop       =   600
  7.    ClientWidth     =   3840
  8.    Height          =   5790
  9.    Left            =   600
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5385
  12.    ScaleWidth      =   3840
  13.    Top             =   255
  14.    Width           =   3960
  15.    Begin VB.PictureBox picHidden 
  16.       AutoRedraw      =   -1  'True
  17.       AutoSize        =   -1  'True
  18.       BorderStyle     =   0  'None
  19.       Height          =   5325
  20.       Left            =   1800
  21.       Picture         =   "Form1.frx":0000
  22.       ScaleHeight     =   355
  23.       ScaleMode       =   3  'Pixel
  24.       ScaleWidth      =   251
  25.       TabIndex        =   3
  26.       Top             =   2400
  27.       Visible         =   0   'False
  28.       Width           =   3765
  29.    End
  30.    Begin VB.PictureBox picXMask 
  31.       AutoRedraw      =   -1  'True
  32.       AutoSize        =   -1  'True
  33.       BorderStyle     =   0  'None
  34.       Height          =   1605
  35.       Left            =   2280
  36.       Picture         =   "Form1.frx":8301
  37.       ScaleHeight     =   107
  38.       ScaleMode       =   3  'Pixel
  39.       ScaleWidth      =   91
  40.       TabIndex        =   1
  41.       Top             =   1800
  42.       Visible         =   0   'False
  43.       Width           =   1365
  44.    End
  45.    Begin VB.PictureBox picX 
  46.       AutoRedraw      =   -1  'True
  47.       AutoSize        =   -1  'True
  48.       BorderStyle     =   0  'None
  49.       Height          =   1605
  50.       Left            =   2760
  51.       Picture         =   "Form1.frx":F69F
  52.       ScaleHeight     =   107
  53.       ScaleMode       =   3  'Pixel
  54.       ScaleWidth      =   91
  55.       TabIndex        =   0
  56.       Top             =   1320
  57.       Visible         =   0   'False
  58.       Width           =   1365
  59.    End
  60.    Begin VB.PictureBox picCanvas 
  61.       AutoRedraw      =   -1  'True
  62.       AutoSize        =   -1  'True
  63.       Height          =   5385
  64.       Left            =   0
  65.       Picture         =   "Form1.frx":16A3D
  66.       ScaleHeight     =   355
  67.       ScaleMode       =   3  'Pixel
  68.       ScaleWidth      =   251
  69.       TabIndex        =   2
  70.       Top             =   0
  71.       Width           =   3825
  72.    End
  73. Attribute VB_Name = "Form1"
  74. Attribute VB_Creatable = False
  75. Attribute VB_Exposed = False
  76. Option Explicit
  77. Private Const MERGEPAINT = &HBB0226
  78. Private Const SRCAND = &H8800C6
  79. Private Const SRCCOPY = &HCC0020
  80. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  81. ' Variables for positioning the image.
  82. Dim OldX As Single
  83. Dim OldY As Single
  84. Dim CurX As Single
  85. Dim CurY As Single
  86. Dim OffsetX As Single
  87. Dim OffsetY As Single
  88. Dim PicWid As Single
  89. Dim PicHgt As Single
  90. Dim Xmax As Single
  91. Dim Ymax As Single
  92. Dim Dragging As Boolean
  93. ' Draw the picture at (CurX, CurY).
  94. Private Sub DrawPicture()
  95.     ' Fix the part of the image that was covered.
  96.     BitBlt picCanvas.hDC, _
  97.         OldX, OldY, PicWid, PicHgt, _
  98.         picHidden.hDC, OldX, OldY, SRCCOPY
  99.     OldX = CurX
  100.     OldY = CurY
  101.     ' Paint on the new image.
  102.     BitBlt picCanvas.hDC, _
  103.         CurX, CurY, PicWid, PicHgt, _
  104.         picXMask.hDC, 0, 0, MERGEPAINT
  105.     BitBlt picCanvas.hDC, _
  106.         CurX, CurY, PicWid, PicHgt, _
  107.         picX.hDC, 0, 0, SRCAND
  108.     ' Update the display.
  109.     picCanvas.Refresh
  110. End Sub
  111. ' Save picCanvas's original bitmap bytes,
  112. ' initialize values, and draw the initial picture.
  113. Private Sub Form_Load()
  114.     ' Make the form fit the picture.
  115.     Width = (Width - ScaleWidth) + picCanvas.Width
  116.     Height = (Height - ScaleHeight) + picCanvas.Height
  117.     PicWid = picX.ScaleWidth
  118.     PicHgt = picX.ScaleHeight
  119.     Xmax = picCanvas.ScaleWidth - PicWid
  120.     Ymax = picCanvas.ScaleHeight - PicHgt
  121.     OldX = 30
  122.     OldY = 30
  123.     CurX = 30
  124.     CurY = 30
  125.     DrawPicture
  126. End Sub
  127. Private Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  128.     ' See if this point corresponds to
  129.     ' a black point on the mask.
  130.     If picXMask.Point(x - CurX, y - CurY) <> vbBlack Then Exit Sub
  131.     ' Start dragging.
  132.     Dragging = True
  133.     OffsetX = CurX - x
  134.     OffsetY = CurY - y
  135. End Sub
  136. ' Continue dragging.
  137. Private Sub picCanvas_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  138.     If Not Dragging Then Exit Sub
  139.     CurX = x + OffsetX
  140.     CurY = y + OffsetY
  141.     If CurX < 0 Then CurX = 0
  142.     If CurX > Xmax Then CurX = Xmax
  143.     If CurY < 0 Then CurY = 0
  144.     If CurY > Ymax Then CurY = Ymax
  145.     DrawPicture
  146. End Sub
  147. ' Stop dragging.
  148. Private Sub picCanvas_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  149.     Dragging = False
  150. End Sub
  151.